using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Collections;

namespace Scalextric
{
    public class DriverHandset
    {
        public int Power { get; set; }
        public bool ChangeLane { get; set; }
        public bool Brake { get; set; }

        public DriverHandset(byte data) //assumes 8 bits NOT 10
        {
            BitArray bData = new BitArray(data);
            if (bData.Count != 8)
                throw new Exception();
            Brake = bData[7];
            ChangeLane = bData[6];
            bool[] pBools = new bool[6];
            for (int i = 0; i < 6; i++)
            {
                pBools[i] = bData[i];
            }
            BitArray pData = new BitArray(pBools);
            Power = getIntFromBitArray(pData);
        }

        private int getIntFromBitArray(BitArray bitArray)
        {
            int[] array = new int[1];
            bitArray.CopyTo(array, 0);
            return array[0];
        }

        public byte ToByte() //complete
        {
            //convert number to 4 bit array 
            bool[] vals = new bool[2];
            vals[0] = ChangeLane;
            vals[1] = Brake;
            //BitArray rData = new BitArray()
            return Byte.MaxValue;
        }
    }
}
